﻿import Taro, { Component } from '@tarojs/taro'
import { Swiper, SwiperItem, Image, View, Text } from '@tarojs/components'
import '../../assets/common.scss'
import CommonJs from '../../utils/common'
import './pointsdetails.scss'
import cat04 from '../../assets/kedouimg01/sckf.png'
import xl from '../../assets/kedouimg01/xl.png'
import goto from '../mall/images/goto01.png'

export default class Index extends Component {
  constructor(props) {
    super(props);
    this.state = {
		resdata:[],
		result:[],
		pageNumber:0,
		money:0,
		navindex:1,
		islisyr:0,
		createDateEnd:'',
    }
  }
  config = {
    navigationBarTitleText: '消费金'
  }
  componentWillMount () {
	var money =this.$router.preload.money;
	this.setState({
		money:money
	  })
	this.getalldate()
	this.getdate(0)
  }
  componentDidShow () {
  	
  }
  getalldate(){
	var _this = this;
	var url = '/crm/papi/v1.9/currency?assetType=XFJ'
	CommonJs.ajaxRequest(url,'','GET',function(res){
		if (res.data.length>0) {
			var resdata = _this.state.resdata
			resdata = res.data[0]
			  _this.setState({
				resdata: resdata,
			  })     
		  } 
		},"wfw")
}
   getdate(pageNumber){
	var _this=this
	if(_this.state.createDateEnd != ''){
		var url = '/crm/papi/v1.9/currency?assetType=XFJ'+ '&createDateEnd=' + _this.state.createDateEnd
	}else{
		var url = '/crm/papi/v1.9/currency?assetType=XFJ'
	}
	var dates={}
	var type=this.state.navindex;
	if(type==1){
		dates.inOrOut=true
	}
	else{
		dates.inOrOut=false
	}
	CommonJs.ajaxRequest(url,dates,'GET',function(res){
		if (res.data.length>0) {
			var results = _this.state.result  
			var result = res.data[0].assetTypeDetailsList
			if(pageNumber==0){
			  results=[]
			}
			for(var i = 0; i < result.length; i++){
			  results.push(result[i]);
			}
			  _this.setState({
				result: results,
				pageNumber:1
			  })     
		  } 
		},"wfw")
	}
	changeMoney(val){
		this.setState({
			navindex:val,
			pageNumber:0,
			result:[]
		})
		var _this=this;
		setTimeout(function(){
			_this.getdate(0)
		},600)	
  
	}
	onDateChange(e){
		var _this = this;
	  var createDateEnd = _this.state.createDateEnd
	  var evalue = e.detail.value
		  createDateEnd =evalue
		  _this.setState({
			  result:[],
			  createDateEnd:createDateEnd,
			  islisyr:1
			})
		setTimeout(function(){
			_this.getdate(0)
		},600)
	}
  opendetails(url){
      this.$preload({
        regType:5
      })
      CommonJs.openTo(url)
	}
  render () {
	const result = this.state.result
	const resdata = this.state.resdata
	const money = this.state.money
    return (
      <View className='page'>
    		<ScrollView className='wdt-list' scrollY='true' onScrollToLower={this.loadMore.bind(this,'')}>
       			<View className='wdt-tj'>
       				<View className='wdt-li'>
						   <Text>消费金</Text>
					   <View className='wdt-lis'>
							<Picker mode='date' onChange={this.onDateChange.bind(this)} fields='month'>
                			  <View className='picker'>{this.state.islisyr == 1 ?this.state.createDateEnd : '本月'}<Image className='xl' mode='widthFix' src={xl}></Image></View>
              				</Picker>
						</View>
					   </View>
					  
					<View className='wdt-li02'>{money/100}</View>
					
					<View className='wdt-li03'>
       					<Text className='wdt-r'>本月收入：{!resdata||resdata.length==0 ? '0':resdata.monthTotal.income/100}</Text>
       					<Text className='wdt-l'>本月支出：{!resdata||resdata.length==0 ? '0':resdata.monthTotal.expenditure/100}</Text>
       				</View>
       				{/* <View className='gxj-list'>
       					<View className='gxj-box'>
       						<Text className='wdt-l'>红包收入</Text>
       						<Text className='wdt-value'>1001174.00</Text>
       					</View>
       					<View className='gxj-box'>
       						<Text className='wdt-l'>转让收入</Text>
       						<Text className='wdt-value'>100174.00</Text>
       					</View>
       					
       					<View className='gxj-box'>
       						<Text className='wdt-l'>转换支出</Text>
       						<Text className='wdt-value'>11174.00</Text>
       					</View>
       					<View className='gxj-box'>
       						<Text className='wdt-l'>转换支出</Text>
       						<Text className='wdt-value'>100121174.00</Text>
       					</View>
       					
       				</View> */}
       				
       			</View>
						
						<View className='gxh-oterh'>
	       				<View className='goods-order' onClick={this.opendetails.bind(this,'/pages/my/zrcapital')}>
	       					<Text className=''>转让消费金</Text>
									<Image className="goto" mode="widthFix" src={goto}></Image>
			        	</View>
			      </View>
						
       			<View className='wdt-mx'>
       				<View className='wdt-tit' style="padding-top:0">
       					<Text className={this.state.navindex==1?'tit-li activer':'tit-li'} onClick={this.changeMoney.bind(this,1)}>收入</Text>
       					<Text className={this.state.navindex==2?'tit-li activer':'tit-li'} onClick={this.changeMoney.bind(this,2)}>支出</Text>
       				</View>
       				
       				<View className='qun-mingxibo'>
					   <View className='nodate' style={!result||result.length==0?'':'display:none;'}>暂无数据</View>
						   {result.map((item,index)=>(
	       				<View className='qun-mingxilist'>
			              <View className='qun-mngxicont'>
			                <View className='qun-mngxileft'>
			                  <Text className='qun-minxizngs qun-reanao'>{item.note}</Text>
			                  <Text className='qun-minxizngs qun-minxitit'>{CommonJs.FormatDate(item.createAt,3)}</Text>
			                </View>
			                <View className='qun-mngxiright'>
			                  <Text style="margin-top:0" className={this.state.navindex==1?'qun-minxizngs qun-minxijine':'qun-minxizngs qun-minxijine qun-colors'}>{item.changeAmount/100}</Text>
			                </View>
			              </View>
			          </View>
			          ))}
			         
			        </View>
       			</View>
       	</ScrollView>
      </View>
    )
  }
}

 